package com.ymatou.iapi.userservice.testcase;

import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymatou.iapi.userservice.parameter.SetIdcardBean;
import com.ymatou.iapi.userservice.service.SetIdcardCall;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.model.Userinfoex;
import com.ymttest.database.sqlwapper.JUserWapper;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;
/**
*设置身份证信息
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SetIdcard{
	private static SetIdcardBean setidcardBean;
	private static SetIdcardCall setidcardCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("设置身份证信息");
	}

	@Before
	public void caseUp() {
		setidcardBean=new SetIdcardBean();
		setidcardCall=new SetIdcardCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(setidcardCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	private void verifyDB() {
		List<Userinfoex> ex = new JUserWapper().selectUserinfoexByUid(setidcardBean.getUserId());
//		Logger.debug(FormatUtil.beanToGSONString(ex));
		Logger.verifyEquals(setidcardBean.getIdCardName(),ex.get(0).getIdCardName(),"验证IdCardName");
		Logger.verifyEquals(setidcardBean.getIdCardNum(),ex.get(0).getIdCardNum(),"验证IdCardNum");
		
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetIdcard_001() {
		Logger.start(true,"设置身份证信息成功");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();
			
			setidcardBean.setUserId(userId);
			setidcardBean.setIdCardName(TestDataManager.getChineseName());
			setidcardBean.setIdCardNum(TestDataManager.getCardId(18, 10));
			setidcardCall.setData(setidcardBean);
			setidcardCall.callService();	
			Logger.verifyEquals("true", setidcardCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", setidcardCall.getString("ResponseCode"), "验证ResponseCode");
			verifyDB();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	

	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_SetIdcard_002() {
		Logger.start(true,"不输入userid失败");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
//			Integer userId = urrc.getUserid();
			
//			setidcardBean.setUserId(userId);
			setidcardBean.setIdCardName(TestDataManager.getChineseName());
			setidcardBean.setIdCardNum(TestDataManager.getCardId(18, 10));
			setidcardCall.setData(setidcardBean);
			setidcardCall.callService();	
			Logger.verifyEquals("false", setidcardCall.getString("Success"), "验证Success");
			Logger.verifyEquals("100", setidcardCall.getString("ResponseCode"), "验证ResponseCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SetIdcard_003() {
		Logger.start(true,"已设置身份信息用户再次设置成功");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();
			
			setidcardBean.setUserId(userId);
			setidcardBean.setIdCardName(TestDataManager.getChineseName());
			setidcardBean.setIdCardNum(TestDataManager.getCardId(18, 10));
			setidcardCall.setData(setidcardBean);
			setidcardCall.callService();	
			
			setidcardBean.setIdCardName(TestDataManager.getChineseName());
			setidcardBean.setIdCardNum(TestDataManager.getCardId(18, 10));
			setidcardCall.setData(setidcardBean);
			setidcardCall.callService();	
			
			Logger.verifyEquals("true", setidcardCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", setidcardCall.getString("ResponseCode"), "验证ResponseCode");
			verifyDB();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SetIdcard_004() {
		Logger.start(true,"无此用户失败");
		try {
//			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
//			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
//
//			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
//			String token = registerResult.get("Token").getAsString();
//			Integer userId = urrc.getUserid();
			
			setidcardBean.setUserId(-10);
			setidcardBean.setIdCardName(TestDataManager.getChineseName());
			setidcardBean.setIdCardNum(TestDataManager.getCardId(18, 10));
			setidcardCall.setData(setidcardBean);
			setidcardCall.callService();	
			Logger.verifyEquals("false", setidcardCall.getString("Success"), "验证Success");
			Logger.verifyEquals("100001", setidcardCall.getString("ResponseCode"), "验证ResponseCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_SetIdcard_005() {
		Logger.start(true,"不输入idCardName失败");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();
			
			setidcardBean.setUserId(userId);
//			setidcardBean.setIdCardName(TestDataManager.getChineseName());
			setidcardBean.setIdCardNum(TestDataManager.getCardId(18, 10));
			setidcardCall.setData(setidcardBean);
			setidcardCall.callService();	
			Logger.verifyEquals("false", setidcardCall.getString("Success"), "验证Success");
			Logger.verifyEquals("100", setidcardCall.getString("ResponseCode"), "验证ResponseCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_SetIdcard_006() {
		Logger.start(true,"不输入idCardNum失败");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();
			
			setidcardBean.setUserId(userId);
			setidcardBean.setIdCardName(TestDataManager.getChineseName());
//			setidcardBean.setIdCardNum(TestDataManager.getCardId(18, 10));
			setidcardCall.setData(setidcardBean);
			setidcardCall.callService();	
			Logger.verifyEquals("false", setidcardCall.getString("Success"), "验证Success");
			Logger.verifyEquals("100", setidcardCall.getString("ResponseCode"), "验证ResponseCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_SetIdcard_007() {
		Logger.start(true,"idCardName过长");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();
			
			setidcardBean.setUserId(userId);
			setidcardBean.setIdCardName("abcdefgabcdefgabcdefgabcdefgabcdefgabcdefg");
			setidcardBean.setIdCardNum(TestDataManager.getCardId(18, 10));
			setidcardCall.setData(setidcardBean);
			setidcardCall.callService();	
			Logger.verifyEquals("false", setidcardCall.getString("Success"), "验证Success");
			Logger.verifyEquals("100", setidcardCall.getString("ResponseCode"), "验证ResponseCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_SetIdcard_008() {
		Logger.start(true,"idCardNum过长");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();
			
			setidcardBean.setUserId(userId);
			setidcardBean.setIdCardName(TestDataManager.getChineseName());
			setidcardBean.setIdCardNum(TestDataManager.getCardId(18, 10)+1234567890);
			setidcardCall.setData(setidcardBean);
			setidcardCall.callService();	
			Logger.verifyEquals("false", setidcardCall.getString("Success"), "验证Success");
			Logger.verifyEquals("100", setidcardCall.getString("ResponseCode"), "验证ResponseCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}